package com.crape.common.constants;

import java.util.HashMap;
import java.util.Map;

public class MessageCode {

    public static String               key                          = "messageCode";
    public static Map<Integer, String> codeMap                      = new HashMap<Integer, String>();

    public static Integer              SUCCES                       = 1000000000;
    public static Integer              SUCCES_SAVE                  = 1000000001;
    public static Integer              SUCCES_UPDATE                = 1000000002;
    public static Integer              PARAMS_IS_NULL               = 1000000003;
    public static Integer              DATA_NOT_EXSIT               = 1000000004;
    static {
        MessageCode.put(SUCCES, "处理成功！");
        MessageCode.put(SUCCES_SAVE, "保存成功！");
        MessageCode.put(SUCCES_UPDATE, "更新成功！");
        MessageCode.put(PARAMS_IS_NULL, "参数为空！");
        MessageCode.put(DATA_NOT_EXSIT, "数据已不存在！");
    }

    public static Integer              TOPIC_ARTICLE_TITLE_NULL     = 1000001001;
    public static Integer              TOPIC_ARTICLE_CONTENT_NULL   = 1000001002;
    public static Integer              TOPIC_ARTICLE_SUBJECT_NULL   = 1000001003;
    public static Integer              TOPIC_ARTICLE_LABEL_NULL     = 1000001004;
    public static Integer              TOPIC_ARTICLE_IS_NULL     	= 1000001005;
    public static Integer              TOPIC_ARTICLE_UNPUBLISHED    = 1000001006;
    static {
        MessageCode.put(TOPIC_ARTICLE_TITLE_NULL, "文章标题不能为空！");
        MessageCode.put(TOPIC_ARTICLE_CONTENT_NULL, "文章内容不能为空！");
        MessageCode.put(TOPIC_ARTICLE_SUBJECT_NULL, "文章相关主题不能为空！");
        MessageCode.put(TOPIC_ARTICLE_LABEL_NULL, "文章标签不能为空！");
        MessageCode.put(TOPIC_ARTICLE_IS_NULL, "文章不存在！");
        MessageCode.put(TOPIC_ARTICLE_UNPUBLISHED, "文章未发布！");
    }

    public static Integer              FAQ_QUESTION_TITLE_NULL      = 1000002001;
    public static Integer              FAQ_QUESTION_COMPLEMENT_NULL = 1000002002;
    public static Integer              FAQ_QUESTION_LABEL_NULL      = 1000002003;
    static {
        MessageCode.put(FAQ_QUESTION_TITLE_NULL, "问题不能为空！");
        MessageCode.put(FAQ_QUESTION_COMPLEMENT_NULL, "问题补充说明不能为空！");
        MessageCode.put(FAQ_QUESTION_LABEL_NULL, "问题标签不能为空！");
    }

    private static void put(Integer code, String message) {
        if (code == null || message == null) {
        } else {
            if (codeMap.get(code) != null) {
                throw new IllegalArgumentException("MessageCode pub error, this code has exsit! ");
            }
            codeMap.put(code, message);
        }
    }
}
